package org.simple.web.jwt;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * 项目名称：web-security-jwt
 * 类名称：UserAuthService
 * 类描述：UserAuthService
 * 创建时间：2018/9/13
 *
 * @author guihuo   (E-mail:1620657419@qq.com)
 * @version v1.0
 */
@Component
public class UserAuthService implements UserDetailsService {
		static String sname;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    	return new MyUser(username,username);
    }
    
    
    class MyUser implements UserDetails {
        private String username;
        private String password;
        public MyUser(String username, String password) {
            this.username = username;
            this.password = password;
        }

        @Override
        public Collection<? extends GrantedAuthority> getAuthorities() {
            return new ArrayList<>();
        }

        @Override
        public String getPassword() {
            return password;
        }

        @Override
        public String getUsername() {
            return username;
        }

        @Override
        public boolean isAccountNonExpired() {
            return true;
        }

        @Override
        public boolean isAccountNonLocked() {
            return true;
        }

        @Override
        public boolean isCredentialsNonExpired() {
            return true;
        }

        @Override
        public boolean isEnabled() {
            return true;
        }
    }
}
